#!/usr/bin/ksh

# Set the time in minutes of filter in NSM
HOWLONGTIME=$1
typeset -u SYSTEMNAME
SYSTEMNAME=$(echo $2| sed 's/ /_/g')
typeset -l lowsid
lowsid=$SYSTEMNAME


if [ "${HOWLONGTIME}" == "" -o "${SYSTEMNAME}" == "" ] ; then
echo "Need 2 parameters: 1st - For how long time to set the filter (minutes), 2nd - system name (SID) or qualifier (in quotes)"
exit 0
fi

echo "Confirm to proceed:"
printf "%45s" "Time to have the filter active from now"
printf "%50s\n" "Qualifier for SAP_SMP source in Tivoli"
printf "%40s" "$HOWLONGTIME minute(s)"
printf "%60s\n" "%$SYSTEMNAME% and %$lowsid%"
typeset -u line=" "
while [ true ] ; do echo "Type Y(y)/N(n) and press ENTER:" ; read line ;  if [ "$line" == "N" ] ; then exit 0 ; fi; if [ "$line" == "Y" ] ; then break ; fi ; done
echo "\n\n\nConnecting to sapsmp01"
sudo -u saunix ssh -q -o BatchMode=yes sapsmp01 'sudo /usr/local/bin/set_Tiv_filter.sh "'$HOWLONGTIME'" "'$SYSTEMNAME'"; sleep 3;  sudo echo Verify the syslog output below from sapsmp01 to see the request for setup the filter in Tivoli; sleep 3; sudo grep "createmwm source=SAP_SMP" /var/adm/syslog/syslog.log | sudo grep  -i "'$SYSTEMNAME'"'  2>&1 

MFHOST=$(grep -i $SYSTEMNAME /usr/local/bin/myprodlist.txt|tail -1)
if [ "$MFHOST" != "" ] ; then
echo "\n\n\nDo you want to setup the Maintenance filter for the host "$MFHOST" ?    Type Y(y)/N(n) and press ENTER:"
read line
if [ "$line" == "Y" ] ; then
sudo -u saunix ssh -q -o BatchMode=yes sapsmp01 'sudo /usr/bin/logger logger -p local5.notice "createmwm source='$MFHOST',duration='$HOWLONGTIME'"; sudo grep "createmwm source='$MFHOST'" /var/adm/syslog/syslog.log'
fi 
else
echo "\n\n\nDo you want to setup the Maintenance filter for the host?    Type HOSTNAME to do it or N(n) to skip and press ENTER:"
read line
if [ "$line" != "N" -a  "$line" != "" ] ; then
MFHOST=$line
echo "\n\n\nConnecting to sapsmp01"
sudo -u saunix ssh -q -o BatchMode=yes sapsmp01 'sudo /usr/bin/logger logger -p local5.notice "createmwm source='$MFHOST',duration='$HOWLONGTIME'"; sudo echo Verify the syslog output below from sapsmp01 to see the request for setup the filter in Tivoli; sleep 3; sudo grep "createmwm source='$MFHOST'" /var/adm/syslog/syslog.log| grep "user:notice" '
fi

fi
echo "Completed"
